﻿using Compass.Wasm.Shared;
using System.Collections.Generic;

namespace Compass.Wpf.ApiServices.Plans;

public interface IPalletService:IBaseService<PalletDto>
{
    Task<ApiResponse<PalletDto>> UpdateStatusesAsync(Guid id, PalletDto dto);
    Task<ApiResponse<List<PalletDto>>> GetAllByMainPlanIdAsync(Guid mainPlanId);
}

public class PalletService :BaseService<PalletDto>, IPalletService
{
    #region ctor
    private const string ServiceName = "Pallet";
    private readonly HttpRestClient _client;
    public PalletService(HttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }
    #endregion

    #region 扩展查询
    public async Task<ApiResponse<PalletDto>> UpdateStatusesAsync(Guid id, PalletDto dto)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Put,
            Route = $"api/{ServiceName}/UpdateStatuses/{id}",
            Param = dto
        };
        return await _client.ExecuteAsync<PalletDto>(request);
    }

    public async Task<ApiResponse<List<PalletDto>>> GetAllByMainPlanIdAsync(Guid mainPlanId)
    {
        var request = new BaseRequest
        {
            Method = RestSharp.Method.Get,
            Route = $"api/{ServiceName}/PackingList/{mainPlanId}"
        };
        return await _client.ExecuteAsync<List<PalletDto>>(request);
    } 
    #endregion
}